/*==================================================
Project:       Targeting Social Programs
Authors:       Diether W. Beuermann
               Bridget Hoffmann        
               Marco Stampini 
               David L. Vargas
               Diego Vera-Cossio
----------------------------------------------------
Creation Date:    May 2023
Modification Date:   
Do-file version:    01
References:          
Output:             
==================================================*/

/* Regular PMT model using all SISBEN varibles and SISBEN income
 This will serve as baseline for comparison		*/


 /*==================================================
               0: Program set up
 ==================================================*/
 *Written on STATA 17
 drop _all
 set varabbrev off	// no variable abbreviations allowed (personal preference)

 ** source dir
 cd "${dir5r}" // graph dir
 
/*==================================================
             Make graphs 
 ==================================================*/

 use "${dir3r}/03_auxiliar/Boostrap_estimates.dta" , clear

 *foreach m_type in "OLS" "lasso_labour" "lasso" {
foreach m_type in "OLS"  {

    *** Gain and losses
    #delimit ;
    tw (connected exclusion_err year if type_m ==  "Baseline", 
            mcolor(red%80) msym(S) lcolor(red%80) )
			(rcap exclusion_err_uci exclusion_err_lci year if type_m ==  "Baseline", 
            lcolor(red%80) )
        (connected exclusion_err year if type_m ==  "Updated", 
            lcolor( ltblue)  mcolor( ltblue) msym(0) lpattern(-))
			(rcap exclusion_err_uci exclusion_err_lci year if type_m ==  "Updated", 
            lcolor( ltblue) lpattern(-))
        (connected exclusion_err year if type_m ==  "Expanded", 
            mcolor(gray%80) msym(T) lcolor(gray%80)) 
		(rcap exclusion_err_uci exclusion_err_lci year if type_m ==  "Expanded", 
            lcolor(gray%80) )	
        (connected exclusion_err year if model_n ==  6 & type_m ==  "`m_type'" , 
            mcolor(black%80) msym(D) lcolor(black%80) ) 
		(rcap exclusion_err_uci exclusion_err_lci year if model_n ==  6 & type_m ==  "`m_type'", 
            lcolor(black%80) )	
			,
		legend(order(1 "Benchmark PMT"		 			
                    3 "Updated PMT - Assets" 					
                    5 "Expanded Coverage"	
                    7 "Dynamic" ) pos(6) row(2))
        ytitle("Exclusion Error")
        xtitle("Year")
        xlabel(2019(1)2021)
        ylabel(20(5)50)
        name(A, replace)
    ;
    #delimit cr
    graph export "F3_performance_a_gainloss_`m_type'_bst.png", as(png) replace width(1200)
    graph export "F3_performance_a_gainloss_`m_type'_bst.pdf", as(pdf) replace 
    

    #delimit ;
    tw (connected inclusion_err year if type_m ==  "Baseline", 
            mcolor(red%80) msym(S) lcolor(red%80))
			(rcap inclusion_err_uci inclusion_err_lci  year if type_m ==  "Baseline", 
            lcolor(red%80))
        (connected inclusion_err year if type_m ==  "Updated", 
            mcolor(ltblue) msym(0) lpattern(-) lcolor(ltblue))
			(rcap inclusion_err_uci inclusion_err_lci year if type_m ==  "Updated", 
            lcolor(ltblue) lpattern(-) )
        (connected inclusion_err year if type_m ==  "Expanded", 
            mcolor(gray%80) msym(T) lcolor(gray%80)) 
			 (rcap inclusion_err_uci inclusion_err_lci year if type_m ==  "Expanded", 
            lcolor(gray%80)) 
        (connected inclusion_err year if model_n ==  6 & type_m ==  "`m_type'" , 
            mcolor(black%80) msym(D) lcolor(black%80)) 
			 (rcap inclusion_err_uci inclusion_err_lci year if model_n ==  6 & type_m ==  "`m_type'" , 
            mcolor(black%80) msym(D) lcolor(black%80)) 
			,
        legend(order(1 "Benchmark PMT"		 			
                    3 "Updated PMT - Assets" 					
                    5 "Expanded Coverage"	
                    7 "Dynamic" ) pos(6) row(2))
        ytitle("Inclusion Error")
        xtitle("Year")
        xlabel(2019(1)2021)
        ylabel(20(5)50)
        name(B, replace)
    ;
	
    #delimit cr
    graph export "F3_performance_b_gainloss_`m_type'_bst.png", as(png) replace width(1200)
    graph export "F3_performance_b_gainloss_`m_type'_bst.pdf", as(pdf) replace 


    #delimit ;
    tw (connected hh_benefits year if type_m ==  "Baseline", 
            mcolor(red%80) msym(S) lcolor(red%80))
		(rcap hh_benefits_uci hh_benefits_lci year if type_m ==  "Baseline", 
             lcolor(red%80))	
        (connected hh_benefits year if type_m ==  "Updated", 
            mcolor(ltblue) msym(0) lpattern(-) lcolor(ltblue))
		        (rcap hh_benefits_uci hh_benefits_lci year if type_m ==  "Updated", 
            lcolor(ltblue))	
        (connected hh_benefits year if type_m ==  "Expanded", 
            mcolor(gray%80) msym(T) lcolor(gray%80))
			 (rcap hh_benefits_uci hh_benefits_lci year if type_m ==  "Expanded", 
            lcolor(gray%80))
        (connected hh_benefits year if model_n ==  6 & type_m ==  "`m_type'" , 
            mcolor(black%80) msym(D) lcolor(black%80))
		        (rcap hh_benefits_uci hh_benefits_lci year if model_n ==  6 & type_m ==  "`m_type'" , 
            lcolor(black%80))	
			,
        legend(order(1 "Benchmark PMT"		 			
                    3 "Updated PMT - Assets" 					
                    5 "Expanded Coverage"	
                    7 "Dynamic" ) pos(6) row(2))
        ytitle("Per-household Transfer ($ USD PPP)")
        xtitle("Year")
        xlabel(2019(1)2021)
        name(D, replace)
    ;
    #delimit cr
    graph export "F3_performance_c_gainloss_`m_type'_bst.png", as(png) replace width(1200)
    graph export "F3_performance_c_gainloss_`m_type'_bst.pdf", as(pdf) replace 


    #delimit ;
    tw (connected crra year if type_m ==  "Baseline", 
            mcolor(red%80) msym(S) lcolor(red%80))
			(rcap crra_uci crra_lci year if type_m ==  "Baseline", 
            lcolor(red%80))
        (connected crra year if type_m ==  "Updated", 
            mcolor(ltblue) msym(0) lpattern(-) lcolor(ltblue))
		        (rcap crra_uci crra_lci year if type_m ==  "Updated", 
             lcolor(ltblue))	
        (connected crra year if type_m ==  "Expanded", 
            mcolor(gray%80) msym(T) lcolor(gray%80)) 
			(rcap crra_uci crra_lci year if type_m ==  "Expanded", 
            lcolor(gray%80)) 
        (connected crra year if model_n ==  6 & type_m ==  "`m_type'" , 
            mcolor(black%80) msym(D) lcolor(black%80)) 
		        (rcap crra_uci crra_lci year if model_n ==  6 & type_m ==  "`m_type'" , 
            lcolor(black%80))	
			,
        legend(order(1 "Benchmark PMT"		 			
                    3 "Updated PMT - Assets" 					
                    5 "Expanded Coverage"	
                    7 "Dynamic" ) pos(6) row(2))
        ytitle("Social Welfare (CRRA: {&rho} = 3)")
        xtitle("Year")
        xlabel(2019(1)2021)
        name(C, replace)
    ;
    #delimit cr
    graph export "F3_performance_d_gainloss_`m_type'_bst.png", as(png) replace width(1200)
    graph export "F3_performance_d_gainloss_`m_type'_bst.pdf", as(pdf) replace 

 }